typedef struct ListNode ListNode; 
struct ListNode* partition(struct ListNode* head, int x) 
{
    //判空
    if(head == NULL)
    {
        return NULL;
    }
    ListNode* lesshead, *lesstail;
    ListNode* greathead, *greattail;
    lesshead = lesstail = (ListNode*)malloc(sizeof(ListNode));
    greathead = greattail = (ListNode*)malloc(sizeof(ListNode));

    ListNode* pcur = head;
    while(pcur)
    {
        if(pcur->val < x)
        {
            //尾插在lesstail之后
            lesstail->next = pcur;
            lesstail = lesstail->next;
        }
        else
        {
            //尾插在greattail之后
            greattail->next = pcur;
            greattail = greattail->next;
        }
        pcur = pcur->next;
    }

    //注意顺序
    greattail->next = NULL;
    lesstail->next = greathead->next;
    ListNode* ret = lesshead->next;
    free(lesshead);
    free(greathead);
    greathead = lesshead = NULL;
    return ret;
}